<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->library('session');
		$session = $this->session->userdata('username');
		if(!$session){
			redirect('/home','location');
		}
	}

	/**
	 * 登陆页面入口
	 * @return [type] [description]
	 */
	function index()
	{
		// 获取ip
		// $this->input->ip_address() 
		// 判断是否是ajax请求
		// $this->input->is_ajax_request() 
		$whriteList = array(
			'dashboard' => 'main.php',
			'behind' => 'behind.php',
			'users' => 'users.php',
			'groupusers' => 'groupusers.php',
			'power' => 'power.php' ,
			'src' => 'src.php',
			'waf_rules' => 'waf_rules.php',
			'waf' => 'waf.php',
			'demo' => 'demo.php'
		);

		$path = $this->input->get('path');
		$data['username'] = $this->session->userdata('username');
		$data['components'] = 'components.php';

		if(empty($path) or !array_key_exists($path, $whriteList)){
			$data['url'] = $whriteList['dashboard'];
		}else{
			$data['url'] = $whriteList[$path];
		}
		$this->load->view('frame',$data);

	}

	/**
	 * 退出登录
	 * @return [type] [description]
	 */
	function logout()
	{
		$this->session->unset_userdata('username');
		redirect('/home','location');
	}
}
